<?php
namespace Home\Controller;
use Think\Controller;

/**
 *
 */
class WebInfoController extends BaseController
{
  function videoList() {
    $list = array('序号', '标题', '类型', '原名称', '图片地址', 'H5地址', '阅读数目', '喜欢数目', '日期', '时长');
    $data['data'] = $list;
    $this->success($data);
  }
  function videoInfo() {
    $videoM = M('video');
    $video = $videoM->field(array('id', 'title', 'titlespelling', 'sourcename', 'imglink', 'url', 'readarts', 'likecount', 'date', 'duration'))->select();
    $data['data'] = $video;
    $this->success($data);
  }
  function videoInsert() {
    $id = I('gId');
    $title = I('gTitle');
    $titlespelling = I('gTitlespelling');
    $sourcename = I('gSourcename');
    $imglink = I('gImglink');
    $url = I('gUrl');
    $readarts = I('gReadarts');
    $likecount = I('gLikecount');
    $date = I('gDate');
    $duration = I('gDuration');

    $video['id'] = $id;
    $video['title'] = $title;
    $video['titlespelling'] = $titlespelling;
    $video['sourcename'] = $sourcename;
    $video['imglink'] = $imglink;
    $video['readarts'] = $readarts;
    $video['likecount'] = $likecount;
    $video['date'] = $date;
    $video['duration'] = $duration;
    if ($id == null) {
      $data['code'] = 999;
      $data['msg'] = 'id不能为空';
      $this->error($data);
    }
    $videoM = M('video');
    $videoM->add($video);
    $this->success($data);
  }
  function videoUpdate() {
    $id = I('gId');
    $key = I('gKey');
    $value = I('gValue');
    if ($id == null) {
      $data['code'] = 1001;
      $data['msg'] = '参数为空';
      $this->error($data);
    }
    $arr = array('id', 'title', 'titlespelling', 'sourcename', 'imglink', 'url', 'readarts', 'likecount', 'date', 'duration');
    $videoM = M('video');
    $video = $videoM->where(array('id'=>$id))->find();
    if ($video != null) {
      $video[$key] = $value;
      $videoM->save($video);
      $this->success($data);
    }
    else {
      $data['code'] = 999;
      $data['msg'] = 'id不存在';
      $this->error($data);
    }
  }
  function videoDelete() {
    $id = I('gId');
    if ($id == null) {
      $data['code'] = 1001;
      $data['msg'] = '参数为空';
      $this->error($data);
    }
    $videoM = M('video');
    $videoM->where(array('id' => $id))->delete();
    $this->success($data);
  }
}

?>
